/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package locusts.server.collisions;

import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import locusts.common.entities.Entity;
import locusts.common.entities.EntityData;

/**
 *
 * @author hamish
 */
public class CollidableEntityAdapter implements Collidable {

    private Entity entity;
    private EntityData data;
    
    public CollidableEntityAdapter(Entity entity, EntityData data) {
        this.entity = entity;
        this.data = data;
    }

    public Entity getEntity() {
        return entity;
    }

    public EntityData getData() {
        return data;
    }

    public int getTypeId() {
        return entity.getTypeId();
    }

    public int getId() {
        return entity.getId();
    }
    
    public double getX() {
        return entity.getX();
    }

    public double getY() {
        return entity.getY();
    }

    public Shape getShape() {
        return data.getShape();
    }

    public Area getArea() {
        return data.getArea();
    }

    public Area geTransformedArea() {
        return data.getArea().createTransformedArea(entity.getAffineTransform());
    }

    public double getMaxRadius() {
        return data.getMaxRadius();
    }

    public boolean isAlive() {
        return entity.isAlive();
    }

    public void setAlive(boolean alive) {
        entity.setAlive(alive);
    }

    public void setPosition(double x, double y) {
        entity.setPosition(x, y);
    }

    public double getOrientation() {
        return entity.getOrientation();
    }

    public void setOrientation(double orientation) {
        entity.setOrientation(orientation);
    }


    public void setX(double x) {
        entity.setX(x);
    }

    public void setY(double y) {
        entity.setY(y);
    }

    public double getEnergy() {
        return entity.getEnergy();
    }

    public void setEnergy(double energy) {
        entity.setEnergy(energy);
    }

    public AffineTransform getAffineTransform() {
        final AffineTransform at = new AffineTransform();
        at.translate(getX(), getY());
        at.rotate(getOrientation());
        return at;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) return false;
        if (getClass() != obj.getClass()) return false;
        final CollidableEntityAdapter other = (CollidableEntityAdapter) obj;
        if (this.entity != other.entity &&
                (this.entity == null || !this.entity.equals(other.entity)))
            return false;
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 31 * hash + (this.entity != null ? this.entity.hashCode() : 0);
        return hash;
    }

    
}
